﻿<?php require_once('Connections/satphp.php'); ?>
<?php
function erro(){include "error-page.html";exit;};
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;


if (!isset($_GET['idturma']) || $_GET['idturma']=='')erro();
else $idturma = $_GET['idturma'];

mysql_select_db($database_satphp, $satphp);
	$query_Recordset1 = "SELECT * 
						FROM forum 
						LEFT JOIN aluno 
							ON (forum.idaluno = aluno.idaluno)
						WHERE 
							forum.idturma = $idturma 
							AND 
							forum.idpai = 0";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $satphp) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Forum | SATPHP</title>
</head>

<body>
<table border="1" align="center" width="600">
  <tr>
    <td>Autor:</td>
    <td>Titulo</td>
    <td>Mensagem</td>
    <td>Data</td>
  </tr>
  <?php do { ?>
    <tr>
      <!-- <td><?php echo $row_Recordset1['idforum']; ?></td> -->
      <td><?php echo $row_Recordset1['nome']; ?></td>
      <td><a href="forum-display.php?idturma=<?php echo $idturma;?>&post=<?php echo $row_Recordset1['idforum']; ?>"><?php echo strip_tags($row_Recordset1['titulo']); ?></a></td>
      <td><a href="forum-display.php?idturma=<?php echo $idturma;?>&post=<?php echo $row_Recordset1['idforum']; ?>"><?php echo strip_tags($row_Recordset1['mensagem']); ?></a></td>
      <td><?php echo $row_Recordset1['datapostagem']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    <tr>
    	<td align="right" colspan="6"><button onclick="location.href='forum-post.php?idturma=<?php echo $idturma;?>'" />Novo post</button></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
